#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 10, M = 1e5 + 10;
int par[N];
int find(int x) { return par[x] = (x == par[x]) ? x : find(par[x]); }
struct edge {
  int u, v, w;
  bool operator<(const edge &t) const { return w < t.w; }
} E[M];
int n, m, rt;
int cnt;
int main() {
  cin >> n >> m >> rt;
  for (int i = 0; i <= n; ++i) par[i] = i;
  for (int i = 0; i < m; ++i) cin >> E[i].u >> E[i].v >> E[i].w;
  sort(E, E + m);
  for (int i = 0; i < m; ++i) {
    auto [u, v, w] = E[i];
    u = find(u);
    v = find(v);
    if (u == v) continue;
    par[u] = v;
    cnt++;
    if (cnt == n - 1) {
      cout << w << endl;
      return 0;
    }
  }
}
